<template>
  <div>
    <h1>登录</h1>
    <div>
      <el-form label-width="80px" :model="formLabelAlign">
        <el-form-item label="用户id">
          <el-input v-model="formLabelAlign.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="formLabelAlign.password"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <el-button type="primary" @click="submit">提交</el-button>
    <div style="font-size: 0.1em;color: rgba(255, 0, 0, 0.384);margin-top: 3em;" @click="register">没有账户？点击这里注册一个</div>
  </div>
</template>

<script>
export default {
  name: "loginCom",
  data() {
    return {
      formLabelAlign: {},
    };
  },
  methods: {
    async submit() {
      const result = await this.$store.dispatch('login',this.formLabelAlign)
      console.log('resultresultresultresultresultresultresultresultresult',result);
      if(result.code == 200){
          localStorage.setItem('token',result.token)
          localStorage.setItem('userInfo',JSON.stringify(result.data))
          this.$router.replace({
            path: '/'
          })
      }
    },
    register() {
      this.$router.replace({
        path: '/register'
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
